package com.accp.crm.service;

import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.hibernate.SessionFactory;

import com.accp.crm.dao.CommonDAO;
import com.accp.crm.entity.SysRight;
import com.accp.crm.entity.SysRole;
import com.accp.crm.entity.SysUser;



public class UserService implements IUserService {
   
	private CommonDAO<SysUser> userDAO;
	
    public void setSessionFactory(SessionFactory sessionFactory){
    	
    	userDAO=new CommonDAO<SysUser>(sessionFactory, SysUser.class);
    }
    
    /* (non-Javadoc)
	 * @see com.accp.crm.server.IUserService#findByHQL(com.accp.crm.entity.SysUser)
	 */
    public SysUser findByHQL(SysUser user){
    	
    	String hql="from SysUser u where u.usrName=? and u.usrPassword=?";
    	
    	List list=this.userDAO.findByHQL(hql, user.getUsrName(),user.getUsrPassword());
    	
    	if(list ==null || list.isEmpty()){
			return null;
		}
    	
    	return (SysUser) list.get(0);
    }
    
    public List findAll(){
    	return this.userDAO.findAll();
    }
    
    public void delete(Long id){
    	SysUser user=this.userDAO.findById(id);
    	this.userDAO.delete(user);
    }
    
    public SysUser findByid(Long id){
    	return this.userDAO.findById(id);
    }
    public void add(SysUser user){
    	this.userDAO.save(user);
    }

	@Override
	public void update(SysUser user) {
		this.userDAO.update(user);
	}
}
